package com.sd.controller;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.sd.dao.Orders;

/**
 *
 *
 *
 */
public class OrderController extends Controller {
	public void getList(){
		String sql = "select * from orders";
		renderJson(Orders.dao.find(sql));
	}
	/**
	 * 	customer_id			int(11)			NO	PRI		auto_increment
		customer_name		varchar(64)		YES			
		customer_address	varchar(255)	YES			
		customer_tel		varchar(64)		YES			
		customer_email		varchar(255)	YES			
		customer_fax		varchar(64)		YES			
		customer_qq			varchar(32)		YES			
	 * Parameters:customer.customer_id,customer.customer_name,customer.customer_address,customer.customer_tel,customer.customer_email,
	 * customer.customer_fax,customer.customer_fax,customer.customer_qq
	 */
	public void save(){
		Map<String, Object> map = new HashMap<String, Object>();
		Boolean flag = false;
		try{
			flag = getModel(Orders.class).save();
		}catch (Exception e) {
			e.printStackTrace();
		}
		if(flag){
			map.put("result", "true");
			map.put("message", "保存成功");
		}else{
			map.put("result", "false");
			map.put("message", "保存失败");
		}
		renderJson(map);
	}
	 /**
	  * Parameters:customer.customer_id
	  */
	public void delete(){
		Map<String, Object> map = new HashMap<String, Object>();
		int flag = 0;
		int id = getParaToInt("orders.order_id");
		try{
			flag = Db.update("delete from orders where order_id = ?",id);
		}catch (Exception e) {
			e.printStackTrace();
		}
		if(flag>0){
			map.put("result", "true");
			map.put("message", "删除成功");
		}else{
			map.put("result", "false");
			map.put("message", "删除失败");
		}
		renderJson(map);
	}
	/**
	 * 
	 * Parameters:customer.customer_id,customer.customer_name,customer.customer_address,customer.customer_tel,customer.customer_email,
	 * customer.customer_fax,customer.customer_fax,customer.customer_qq
	 * customer.customer_id必填
	 */
	public void update(){
		Map<String, Object> map = new HashMap<String, Object>();
		Boolean flag = false;
		try{
			flag = getModel(Orders.class).update();
		}catch (Exception e) {
			e.printStackTrace();
		}
		if(flag){
			map.put("result", "true");
			map.put("message", "保存成功");
		}else{
			map.put("result", "false");
			map.put("message", "保存失败");
		}
		renderJson(map);
	}
}



